﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using Portal.Environment;
using Portal.Language;
using Portal.Interface;

namespace Portal.CDSP
{
    public class FFooterWP : WebPart
    {
        #region Properties
        public override string WebPartId
        {
            get
            {
                return "WebSite.FooterWP";
            }
        }

        public override string WebPartFolder
        {
            get
            {
                return "Portal.CDSP";
            }
        }

        public override string Title
        {
            get
            {
                return GetText("FTitle", "SoYT-Bài viết tĩnh");
            }
        }

        public override ViewCls[] Views
        {
            get
            {
                return new ViewCls[]{
                    new ViewCls("Default",GetText("Default","Trang liên hệ"),0),
                    new ViewCls("FooterView",GetText("FooterView","Hiển thị footer."),1),                    
                };
            }
        }


        public override string NameSpace
        {
            get
            {
                return "Portal.CDSP";
            }
        }

        public override string ClassName
        {
            get
            {
                return "FFooterWP";
            }
        }
        #endregion

        private string ClientRenderWebPartDefault(string TabModuleId, string HasPorlet)
        {
            TabModuleCls TabModuleCls = new TabModuleBLL().CreateModelFromXml(TabModuleId);
            FFooterCls HtmlCls = new FFooterBLL().CreateModel(Environments.ActiveLanguage, TabModuleCls.Id);
            if (HtmlCls != null)
            {
                string html =
                        "<div class=\"html_text\">" + HtmlCls.Body + "" +
                        "</div>";
                return html;
            }
            else return GetText("NotFoundAnyHtml", "Không tìm thấy bài viết nào!");
        }

        private string ClientRenderFooter(string TabModuleId, string HasPorlet)
        {
            TabModuleCls TabModuleCls = new TabModuleBLL().CreateModelFromXml(TabModuleId);
            FFooterCls HtmlCls = new FFooterBLL().CreateModel(Environments.ActiveLanguage, TabModuleCls.Id);

            StringBuilder Html = new StringBuilder();
            Html.Append(
                "<div class=\"foot-content\">\n"
                );
            if (HtmlCls != null)
            {

                Html.Append(
                        HtmlCls.Body);
            }
            else
            {
                Html.Append(
                "<span>Không tìm thấy bài viết nào!<span>");
            }
            Html.Append("</div>");
            return Html.ToString();
        }

        [AjaxPro.AjaxMethod]
        public override string ClientRenderWebPart(string BelongSite, string TabModuleId, string ViewName, string HasPorlet, LoadParamCls loadParamCls)
        {
            try
            {
                if (ViewName.Equals("Default"))
                {
                    return ClientRenderWebPartDefault(TabModuleId, HasPorlet);
                }

                if (ViewName.Equals("FooterView"))
                {
                    return ClientRenderFooter(TabModuleId, HasPorlet);
                }

                return GetText("ViewNotFound", "Không tìm thấy View [" + ViewName + "]");
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }
        }

        public override DataTable ReadingDataService(string belongSite, string ActiveLanguage, ref string IdField, ref string SubjectField)
        {
            IdField = "Id";
            SubjectField = "Subject";
            return new FFooterBLL().ReadingForService(belongSite);
        }

        public override bool AllowFrontService
        {
            get
            {
                return true;
            }
        }
    }
}
